/*gcc -c -o gtkWindow.o gtkWindow.c `pkg-config --cflags --libs gtk+-2.0`*/
#include "mygtk.h"
#include <gtk/gtk.h>

Widget_t *createGTKWindow(int argc, char **argv, char* title, int size[2])
{
	GtkWidget *window;
	/*初始化一个窗口*/
	gtk_init(&argc, &argv);
	/*生成一个指点样式的窗口*/
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	/*设置窗口标题*/
	if (title == NULL)
		gtk_window_set_title(GTK_WINDOW(window), "");
	else
		gtk_window_set_title(GTK_WINDOW(window), title);
	/*设置窗口尺寸*/
	gtk_window_set_default_size(GTK_WINDOW(window), size[0], size[1]);
	/*设置窗口中心显示*/
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	return window;
}

void setIcon(Widget_t* window, const gchar* filename)
{
	GdkPixbuf *icon;
	GError *error = NULL;
	icon = gdk_pixbuf_new_from_file(filename, &error);
	if (!icon) {
		fprintf(stderr, "%s\n", error->message);
		g_error_free(error);
	}
	gtk_window_set_icon(GTK_WINDOW(window), icon);
	g_object_unref(icon);
}

void showWindow(GtkWidget* window)
{
	/*显示窗口*/
	gtk_widget_show_all(window);
	/*将destroy消息绑定到处理函数gtk_main_quit*/
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
	gtk_main();
}

void setPadding(Widget_t* root, int pad)
{
	gtk_container_set_border_width(GTK_CONTAINER(root), pad);
}